﻿#!/bin/sh
# excute script, use : sh /opt/command/init_server/batch_modify_servername_all.sh
echo "==========================================================================="
echo "================ step 1 : modify linux /etc/hostname >>> begin >>> ========"
echo "==========================================================================="
echo "CNT7XCEPHD02" > /etc/hostname
# show result
echo "show result"
cat /etc/hostname
echo "==========================================================================="
echo "================ step 1 : modify linux /etc/hostname >>> end   >>> ========"
echo "==========================================================================="
echo ""
echo ""
echo "==========================================================================="
echo "================ step 2 : modify linux /etc/hosts >>> begin >>> ==========="
echo "==========================================================================="
# echo "" > /etc/hosts
cat > /etc/hosts << 'EOF'
::1            localhost

192.168.3.51   CNT7XCEPHD01
192.168.3.52   CNT7XCEPHD02
192.168.3.53   CNT7XCEPHD03
192.168.3.54   CNT7XCEPHD04
192.168.3.55   CNT7XCEPHD05
192.168.3.56   CNT7XCEPHD06
192.168.3.57   CNT7XCEPHD07
192.168.3.58   CNT7XCEPHD08
192.168.3.59   CNT7XCEPHD09
192.168.3.60   CNT7XCEPHD10
EOF
 
# show result
echo "show result"
cat /etc/hosts
echo "==========================================================================="
echo "================ step 2 : modify linux /etc/hosts >>> end   >>> ==========="
echo "==========================================================================="
echo ""
echo ""
echo "==========================================================================="
echo "================ step 3 : delete linux /etc/../eno_invalid >>> begin >>> =="
echo "==========================================================================="
strPath_Invalid=$(find /etc/sysconfig/network-scripts/ -name 'ifcfg-en*')
echo $strPath_Invalid
rm -rf $strPath_Invalid
# show result
echo "show result"
ls -al $strPath_Invalid
echo "==========================================================================="
echo "================ step 3 : delete linux /etc/../eno_invalid >>> begin >>> =="
echo "==========================================================================="
echo ""
echo ""
echo "==========================================================================="
echo "================ step 4 : modify linux /etc/../eno01 >>> begin >>> ========"
echo "==========================================================================="
# echo "" > /etc/sysconfig/network-scripts/ifcfg-eno01
touch /etc/sysconfig/network-scripts/ifcfg-eno01
echo "DEVICE=\"eno01\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "NAME=\"eno01\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "BOOTPROTO=\"static\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "BROADCAST=\"192.168.3.225\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "DNS1=\"192.168.3.1\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "GATEWAY=\"192.168.3.1\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "HWADDR=\"00:50:56:3B:49:A0\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "IPADDR=\"192.168.3.52\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "IPV6INIT=\"yes\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "IPV6_AUTOCONF=\"yes\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "NETMASK=\"255.255.255.0\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "NM_CONTROLLED=\"yes\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "ONBOOT=\"yes\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "TYPE=\"Ethernet\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
echo "UUID=\"11cca6ba-ceph-514d-xd1e-1ecee435bd52\"" >> /etc/sysconfig/network-scripts/ifcfg-eno01
# show result
echo "show result"
cat /etc/sysconfig/network-scripts/ifcfg-eno01
echo "==========================================================================="
echo "================ step 4 : modify linux /etc/../eno01 >>> end >>> =========="
echo "===========================================================================" 
# refresh system info and configure
grub2-mkconfig -o /boot/grub2/grub.cfg
service network restart
